package number;

import java.text.DecimalFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.util.Date;
import java.util.Random;

/**
 * @author:Administrator
 * @date:2022/1/19
 * @describe:
 */
public class NumberFormat {

    public static void main(String[] args) {

        //Random random = new Random();
        //System.out.println(random.nextInt(10));
        //System.out.println((int) (Math.random() * 10));

        double area = Math.PI * 1.5 * 1.5;
        DecimalFormat df = new DecimalFormat("#.00");

        System.out.println(area);
        System.out.println(df.format(area));
        System.out.println(String.format("%.2f", area));

        LocalDate date = LocalDate.parse("2022-06-18");
        if (date.isLeapYear()) {
            System.out.println("是闰年");
        } else {
            System.out.println("是平年");
        }
        System.out.println("================================");
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);

        LocalDate birthday = LocalDate.of(1990, 11, 8);
        LocalDate today = LocalDate.now();
        //时间段的类
        Period p = Period.between(birthday, today);
        System.out.println(p.getYears());
        System.out.println("*********************************");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date dt = sdf.parse("1990-09-05 08:00:00");
            long time = dt.getTime();
            System.out.println("时间戳：" + time);
            System.out.println(dt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}












